#include "driver_key.h"

volatile unsigned int key=0;

void key_scan(void)
{
  unsigned int temp1 = 0;
  unsigned int temp2 = 0;
  volatile unsigned int i;

  if(!(pPIO->PDATF & (1<<5) ) ){temp1 |= (1<<0);}  //key0 sw_mid
  if(!(pPIO->PDATG & (1<<6) ) ){temp1 |= (1<<1);}  //key1 sw_up
  if(!(pPIO->PDATG & (1<<5) ) ){temp1 |= (1<<2);}  //key2 sw_down
  if(!(pPIO->PDATE & (1<<0) ) ){temp1 |= (1<<3);}  //key3 sw_left
  if(!(pPIO->PDATG & (1<<7) ) ){temp1 |= (1<<4);}  //key4 sw_right
  if(!(pPIO->PDATF & (1<<6) ) ){temp1 |= (1<<5);}  //key5 sw_menu
  if(!(pPIO->PDATC & (1<<2) ) ){temp1 |= (1<<6);}  //key6 sw_play
  
  for(i=0;i<50000;i++);

  if(!(pPIO->PDATF & (1<<5) ) ){temp2 |= (1<<0);}  //key0 sw_mid
  if(!(pPIO->PDATG & (1<<6) ) ){temp2 |= (1<<1);}  //key1 sw_up
  if(!(pPIO->PDATG & (1<<5) ) ){temp2 |= (1<<2);}  //key2 sw_down
  if(!(pPIO->PDATE & (1<<0) ) ){temp2 |= (1<<3);}  //key3 sw_left
  if(!(pPIO->PDATG & (1<<7) ) ){temp2 |= (1<<4);}  //key4 sw_right
  if(!(pPIO->PDATF & (1<<6) ) ){temp2 |= (1<<5);}  //key5 sw_menu
  if(!(pPIO->PDATC & (1<<2) ) ){temp2 |= (1<<6);}  //key6 sw_play

  key = temp1 & temp2;
}
